{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e3939fcd",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-09-20\n",
    "* 课程： Python语言\n",
    "* week03\n",
    "---\n",
    "\n",
    "# 本周学习内容\n",
    "\n",
    "> 1. 模块与函数\n",
    "> 2. 变量、赋值、数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6de4cb5d",
   "metadata": {},
   "source": [
    "## 1. 模块\n",
    "\n",
    "> 1. 标准库\n",
    "> 2. 开源模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "73c7edfd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 标准库实践\n",
    "import sys\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9fb97eed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'win32'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.platform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "94dcbb31",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'time' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-b53353a7f9d2>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlocaltime\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'time' is not defined"
     ]
    }
   ],
   "source": [
    "time.localtime"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bcd55fd",
   "metadata": {},
   "source": [
    "* 笔记\n",
    "> 如上错误，在使用某一个模块前，需要先import该模块，否则会出现：NameError: name 'time' is not defined\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3c2c39ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "70165a10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=9, tm_mday=20, tm_hour=10, tm_min=31, tm_sec=32, tm_wday=2, tm_yday=263, tm_isdst=0)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "734888d1",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pyecharts'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-03fe4e4858b8>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 开源模块实践\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mpyecharts\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pyecharts'"
     ]
    }
   ],
   "source": [
    "# 开源模块实践\n",
    "import pyecharts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f389a2a",
   "metadata": {},
   "source": [
    "* 笔记\n",
    "> 下载安装开源模块方法：pip install module_name\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c44e9a0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyecharts\n",
      "  Downloading pyecharts-2.0.4-py3-none-any.whl (147 kB)\n",
      "Collecting prettytable\n",
      "  Downloading prettytable-3.9.0-py3-none-any.whl (27 kB)\n",
      "Collecting simplejson\n",
      "  Downloading simplejson-3.19.1-cp38-cp38-win_amd64.whl (75 kB)\n",
      "Requirement already satisfied: jinja2 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from pyecharts) (2.11.3)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\pc\\anaconda3\\lib\\site-packages (from jinja2->pyecharts) (1.1.1)\n",
      "Requirement already satisfied: wcwidth in c:\\users\\pc\\anaconda3\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n",
      "Installing collected packages: simplejson, prettytable, pyecharts\n",
      "Successfully installed prettytable-3.9.0 pyecharts-2.0.4 simplejson-3.19.1\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b9d49c00",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5bc04c1",
   "metadata": {},
   "source": [
    "## 2. 使用一个模块（函数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8caa07c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4ff02d2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=9, tm_mday=20, tm_hour=10, tm_min=58, tm_sec=1, tm_wday=2, tm_yday=263, tm_isdst=0)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "2799a11f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help 可以查看一个  模块  的帮助文档\n",
    "# help(time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6db73f45",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# help 可以查看一个  函数 的帮助文档（使用文档）\n",
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "cafa5151",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world~\n"
     ]
    }
   ],
   "source": [
    "time.sleep(5)\n",
    "print(\"hello world~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a53cec2f",
   "metadata": {},
   "source": [
    "## 3. 变量、赋值、数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "741c3832",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_name = \"豆豆\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c2ec0ea9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "豆豆\n"
     ]
    }
   ],
   "source": [
    "print(dog_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "caf0517d",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_age = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "439ca6bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(dog_age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d837207a",
   "metadata": {},
   "outputs": [],
   "source": [
    "dog_name = \"毛毛\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3b898b64",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "毛毛\n"
     ]
    }
   ],
   "source": [
    "print(dog_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8d712561",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小明 小明\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "name_10001 = \"小明\"\n",
    "\n",
    "name_10002 = name_10001\n",
    "print(name_10001,name_10002)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "60b91394",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_10001 = \"小兰\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f98a913b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小兰 小明\n"
     ]
    }
   ],
   "source": [
    "print(name_10001,name_10002)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08a41f14",
   "metadata": {},
   "source": [
    "## 条件判断 与 循环遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "80beb7c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，你的身份信息不对，无法开门~\n"
     ]
    }
   ],
   "source": [
    "if dog_name == \"花花\":\n",
    "    print(\"欢迎回家~\")\n",
    "else:\n",
    "    print(\"对不起，你的身份信息不对，无法开门~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbe0c8b2",
   "metadata": {},
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1581cfd9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
